<template>
  <view>
    <!-- 未选择收货地址 -->
    <view class="btnAddress" v-if="JSON.stringify(addressInfo) === '{}'">
      <button type="primary" size="mini" @click="chooseAddress">请选择收货地址+</button>
    </view>
    <!-- 已选择收货地址 -->
    <view class="userInfo" v-else @click="chooseAddress">
      <view class="row1">
        <view class="userName">收货人：{{addressInfo.userName}}</view>
        <view class="phone">
          电话：{{addressInfo.telNumber}}
          <uni-icons type="right" size="16"></uni-icons>
        </view>
      </view>
      <view class="row2">
       <view class="address">收货地址：{{addStr}}</view>
      </view>
    </view>
    <image src="/static/cart_border@2x.png" class="address-border"></image>
  </view>
</template>

<script>
  import {mapState, mapMutations, mapGetters} from 'vuex'
  export default {
    name:"Address",
    data() {
      return {
  
      };
    },
    methods: {
      ...mapMutations("addressAbout", ['UPDATEADDRESS']),
      ...mapState("userAbout", ['token']),
      // 获取收货信息
      chooseAddress() {
        var _this = this
        if (this.token !== '') {
          // 获取地址
          uni.chooseAddress({
            success(res) {
              _this.UPDATEADDRESS(res)
            }
          })
        } else {
          uni.showModal({
            content: "请先登录",
            confirmText: "去登录",
            success(res) {
              if (res.confirm) {
                uni.switchTab({
                  url: "/pages/my/my"
                })
              }
            }
          })
        } 
      }
    },
    computed: {
      ...mapState('addressAbout', ['addressInfo']),
      ...mapGetters('addressAbout', ['addStr'])
    }
  }
</script>

<style lang="scss">
  .address-border {
    display: block;
    width: 100%;
    height: 5px;
  }
  .btnAddress {
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .userInfo {
    padding: 0 5px;
    height: 90px;
    display: flex;
    font-size: 14px;
    flex-direction: column;
    justify-content: center;
    .row1 {
      display: flex;
      justify-content: space-between;
      .userName {}
      .phone {
        margin-right: 5px;
      }
    }
    .row2 {
      margin-top: 8px;
      .address {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
  }
</style>